package com.itxiuyixiu.entity.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.itxiuyixiu.entity.enums.AccountState;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Admin implements Cloneable {
    /**
     * id
     */
    private Integer adminId;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    @JsonIgnore
    private String password;
    /**
     * 权限
     *
     * <p>假如有多个权限，使用英文逗号分割</p>
     */
    private String authorities;
    /**
     * 邮箱
     */
    private String adminEmail;
    /**
     * 头像
     */
    private String headImage;
    /**
     * 昵称
     */
    private String nickName;
    /**
     * 创建时间
     */
    private LocalDateTime gmtCreated;
    /**
     * 修改时间
     */
    private LocalDateTime gmtModified;
    /**
     * 账号状态
     */
    private AccountState accountState;

    public void addAuthority(String authority) {
        authorities += "," + authority;
    }

    @JsonIgnore
    public boolean isEnabled() {
        return this.accountState.compare(AccountState.PASSED) >= 0;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
